package com.sample.library.portlet;

import javax.portlet.RenderRequest;
import javax.portlet.RenderResponse;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.web.portlet.ModelAndView;
import org.springframework.web.portlet.mvc.AbstractController;

import com.liferay.portal.kernel.util.WebKeys;
import com.liferay.portal.model.User;
import com.liferay.portal.theme.ThemeDisplay;

public class MainController extends AbstractController implements InitializingBean {
	public ModelAndView handleRenderRequest(RenderRequest arg0, RenderResponse arg1) throws Exception {
		
		ModelAndView view = new ModelAndView();
		User _user = null;
		ThemeDisplay themeDisplay = (ThemeDisplay)arg0.getAttribute(WebKeys.THEME_DISPLAY);
		if (themeDisplay != null) {
			_user = themeDisplay.getUser();
			_logger.info(_user.getFullName()+"is logged!");
			
		}
		String javaVer = System.getProperty("java.runtime.version");
		String javaVm = System.getProperty("java.vm.name");
		String javaOpt = System.getenv("JAVA_OPTS");
		System.out.println("java.runtime.version="+javaVer);
		System.out.println("java.vm.name="+javaVm);
		System.out.println("JAVA_OPTS="+javaOpt);

		//view.setViewName("book/view");
		//view.setViewName("navigation");
		view.setViewName("home");
		return view;
	}
	
	@Override
	public void afterPropertiesSet() throws Exception {
		// TODO Auto-generated method stub
	}
	private Logger _logger = Logger.getLogger(MainController.class);
}
